import datetime
import pandas as pd


class ParamsPipe:
    # 参数管线，用于在事件回测框架中传递参数，减少查询次数
    def __init__(self):
        self.init_cash = None
        self.today = None
        self.next_day = None
        self.stocks_unsettled = []

    def update_today(self, today: datetime.date):
        self.today = today

    def update_nextDay(self, next_day: datetime.date):
        self.next_day = next_day

    def add_stocks_unsettled(self, stock, size, price, direction):
        self.stocks_unsettled.append((stock, size, price, direction))

    def clear_stocks_unsettled(self):
        self.stocks_unsettled = []

    def update_stocks_unsettled(self, stocks_unsettled: list):
        self.stocks_unsettled = stocks_unsettled

    def get_stocks_unsettled(self) -> pd.DataFrame:
        _a = pd.DataFrame(
            data={
                'code': [i[0] for i in self.stocks_unsettled],
                'size': [i[1] for i in self.stocks_unsettled],
                'price': [i[2] for i in self.stocks_unsettled],
                'direction': [i[3] for i in self.stocks_unsettled]
            }
        )
        return _a
